//
//  FeHandwritingViewController.m
//  FeSpinner
//
//  Created by Nghia Tran on 1/2/15.
//  Copyright (c) 2015 fe. All rights reserved.
//

#import "FeHandwritingViewController.h"
#import "FeHandwriting.h"
#import "UIColor+flat.h"
#import "TranslationViewController.h"
#import "NSObject+alertView.h"

@interface FeHandwritingViewController ()
@property (strong, nonatomic) FeHandwriting *handwritingLoader;

@end

@implementation FeHandwritingViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor colorWithHexCode:@"#ffe200"];
    
    
    
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    _handwritingLoader = [[FeHandwriting alloc] initWithView:self.view];
    [self.view addSubview:_handwritingLoader];
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否体验翻译功能" preferredStyle:(UIAlertControllerStyleAlert)];
    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"是" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
        
        [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(myTask) userInfo:nil repeats:NO];
        [NSTimer scheduledTimerWithTimeInterval:3.5 target:self selector:@selector(pushToTranslateVC) userInfo:nil repeats:NO];
    }];
    
    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"否" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
        
        NSLog(@"没有选择翻译");
    }];
    
    [alertController addAction:action2];
    [alertController addAction:action1];

     [self presentViewController:alertController animated:YES completion:nil];
    
    
    //    [_handwritingLoader showWhileExecutingBlock:^{
    //
    //    } completion:^{
    //        [self.navigationController popToRootViewControllerAnimated:YES];
    //
    //    }];
    
    
}

- (void)pushToTranslateVC
{
//    TranslationViewController *translatingVC = [[TranslationViewController alloc]init];
    UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"Translate" bundle:nil];
    TranslationViewController *translationVC = [mainStoryBoard instantiateViewControllerWithIdentifier:@"TranslationID"];
    [self.navigationController pushViewController:translationVC animated:YES];
    
}

- (void)myTask
{
    // Do something usefull in here instead of sleeping ...
//    sleep(12);
    [_handwritingLoader showWhileExecutingBlock:^{
            } completion:^{
                [self.navigationController popToRootViewControllerAnimated:YES];
                
            }];
}

@end
